Selecting a shape by clicking on the shape or selecting multiple shapes 
by dragging a large rectangle around the shapes. 
The reliable and precise way of selecting a shape depends on the method to compute 
in real time where on the shape the mouse is located


A selected shape can be moved or resized by dragging a selection box or a resize handle. 
The moving or resizing command is generated when the SelectionLS detects
 that the mouse button is pressed on the selection box or the resize handle.


http://www.627utech.com/drawTop/DrawTop_en/api/MoveResizeShape.php#MoveResizeShapeLS

https://books.google.fr/books?id=SSyuJa04uv8C&pg=PA404&lpg=PA404&dq=java+freehand+rectangle&source=bl&ots=ufsGxNxVP4&sig=IVBGAmaU8jAtV2ioEFvNzJR8abg&hl=fr&sa=X&ei=iQTEVIPrDousU6a9g_gK&sqi=2&ved=0CEoQ6AEwBQ#v=onepage&q=java%20freehand%20rectangle&f=false


Drawing a line, handles, resize, dragable 

java rectangle with resize handles

public Rectangle construire(Point p1, Point p3) {
 
    Rectangle aConstruire;
    Point p2,p4;
 
    // p2 : ordonnée de p1, abscisse de p3
    p2.setY(p1.getY());
    p2.setX(p3.getX());
    // p4 : ordonnée de p3, abscisse de p1
    p4.setY(p3.getY());
    p4.setX(p1.getX());
 
    aConstruire = new Rectangle(p1,p2,p3,p4);
    return aConstruire;
 
}



// Rectangle.java: the rectangle class
public class Rectangle{

   // data fields: usually private
   private int length, width;

   // constructor, must be public, no parameters
   public Rectangle(){
      length = 0;
      width = 0;
   }

   // constructor, must be public, two parameters
   public Rectangle(int len, int wid){
      length = len;
      width = wid;
   }

   // accessors, usually public, return data members
   public int getLength(){ return length; }

   public int getWidth(){ return width; }

   // other functions, called methods
   public int getArea(){ return length * width; }

   public int getPerim(){ return 2*length + 2*width; }

   // special toString function
   public String toString(){
      return "Rectangle. width: " +  width +
             ", length: " + length +
             ", area: " + getArea() +
             ", Perim:  " + getPerim();
   }

   
   
   
   public static void main(String args[]) {
      int l, w;

      Rectangle r1 = new Rectangle();
      System.out.println(r1);  // calls toString of r1

      Rectangle r2 = new Rectangle(4,3);
      System.out.println(r2);  // calls toString of r2

      System.out.println("Test getLength, getWidth ...");
      l = r2.getLength();
      w = r2.getWidth();
      System.out.println("  r2 length: " + l);
      System.out.println("  r2 width: " + w);

      System.out.println("Test getArea, getPerim ...");
      System.out.println("  r1 area: " + r1.getArea());
      System.out.println("  r1 Perim: " + r1.getPerim());
      System.out.println("  r2 area: " + r2.getArea());
      System.out.println("  r2 Perim: " + r2.getPerim());
   }
}


class Rectangle
{
double x,y,height,width;

Rectangle()
{
x=0;
y=0;
height=1;
width=1;
}

Rectangle(double x,double y,double height,double width)
{
this.x=x;
this.y=y;
this.height=height;
this.width=width;
}

double getArea()
{
return height*width;
}

double getPerimeter()
{
return 2*(height+width);
}

boolean point(double x,double y)
{
double pointX = x;
double pointY = y;
if (pointX < (this.x + (this.width)) && pointX > (this.x - (this.width)) &&
           pointY < (this.y + (this.height)) && pointY > (this.y - (this.height)))
return true;
else
return false;
}

public static void main(String [] args)
{
Rectangle obj=new Rectangle();
Rectangle obj1=new Rectangle(5,2,10,50);
System.out.println("For default constructor");
System.out.println("Area = "+obj.getArea());
System.out.println("perimeter = "+obj.getPerimeter());
System.out.println("point inside rectangle ="+obj.point(0,0));
System.out.println("For default constructor");
System.out.println("Area = "+obj1.getArea());
System.out.println("perimeter = "+obj1.getPerimeter());
System.out.println("point inside rectangle ="+obj1.point(5,2));

}
}

